package yibao.youyun.com.yibao.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import yibao.youyun.com.yibao.R;

/**
 * Created by woodnaonly on 2015/11/24.
 */
public class ListViewAdapter extends BaseAdapter
{
    private LayoutInflater mInflater;
    private int[] mDatas;
    private  Context context;
    public ListViewAdapter(Context context,int []id)
    {
        super();
        mInflater=LayoutInflater.from(context);
        mDatas=id;
        this.context=context;
    }

    @Override
    public int getCount()
    {
        return mDatas!=null?mDatas.length:0;
    }

    @Override
    public Object getItem(int position)
    {
        return null;
    }

    @Override
    public long getItemId(int position)
    {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.home_layout_list_item, parent,
                    false);
            viewHolder = new ViewHolder();
            viewHolder.mImg = (ImageView) convertView
                    .findViewById(R.id.list_item_imageview);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(context)
                .load(mDatas[position])
                .placeholder(R.mipmap.ic_launcher)
                .resize(180, 100)
                .into(viewHolder.mImg);
        return convertView;
    }
    private final class ViewHolder
    {
        ImageView mImg;
        TextView mTxt1;
        TextView mTxt2;
        TextView mTxt3;
        TextView mTxt4;
    }
}
